
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户列表</title>
</head>
<style type="text/css">
    a{text-decoration: none}
    table {
        border: 1px solid #000;
        border-collapse: collapse;
        margin-top: 0px;
    }

    td {
        border: 1px solid #000;
        height: 10px;
        width: 100px;

    }
</style>
<body>
<%
    request.setCharacterEncoding("UTF-8");
    Connection connection=null;
    Statement statement=null;
    ResultSet resultSet=null;




    try{
        Class.forName("com.mysql.jdbc.Driver");
    }
    catch (ClassNotFoundException e){
        e.printStackTrace();
    }
    try {
        connection= DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone=UTC&characterEncoding=gbk",
                "root",
                "w19971201t");
        statement=connection.createStatement();
       //statement.execute("CREATE TABLE t_user(username VARCHAR(50) PRIMARY KEY ,password VARCHAR(50) )");
        resultSet =statement.executeQuery("SELECT * FROM t_user");
        out.write("<table>"+"<tr>"+"<td>"+"id"+"</td>"+"<td>"+"用户名"+"</td>"+"<td>"+"密码"+"</td>"+"<td>"+"</td>");
        while (resultSet.next()){
            out.write("<table>"+"<tr>"+"<td>"+resultSet.getString(1)+"</td>"+"<td>"+resultSet.getString(2)+"</td>"+"<td>"+resultSet.getString(3)+"</td>"+
                    "<td>"+"<a href='userDelete.jsp?id="+resultSet.getString(1)+"'>"+"删除"+"</a>"+"</td>"+ "</tr>"+"</table>");

        }
    }
catch (SQLException e){
        e.printStackTrace();
}
    finally {
        try {

            connection.close();
            statement.close();

        }
        catch (SQLException e){
            e.printStackTrace();
        }
    }

%>
<a href="userAdd.jsp">添加用户</a></br>
<a href="userSelect.jsp">用户查询</a></br>
<a href="userUpdate.jsp">修改用户</a></br>
</body>
</html>
